---
layout: m1x_rest
title: Response Formats
---



<ul class="introduction-menu">
    <li><a href='#ResponseFormats-RESTAPIResponseFormats'>REST API Response Formats</a>
      <ul>
        <li><a href='#ResponseFormats-XMLFormat'>XML Format</a></li>
        <li><a href='#ResponseFormats-JSONFormat'>JSON Format</a>
          <ul>
            <li><a href='#ResponseFormats-ResponseStructure'>Response Structure</a></li>
            <li><a href='#ResponseFormats-JSONResponses'>JSON Responses</a></li>
          </ul>
        </li>
      </ul>
    </li>
</ul>


<p>If you make a Magento API call, you are guaranteed to receive some kind of a response. If you make a successful call, you will receive an HTTP response with a 200 OK status.</p>

<h1><a name="ResponseFormats-RESTAPIResponseFormats"></a>REST API Response Formats</h1>

<p>You can view the response data from any Magento API call in one of the following two formats:</p>

<ul>
	<li>XML</li>
	<li>JSON</li>
</ul>


<p>The format of returned data is defined in the request header. The format you choose depends on what you are familiar with most or tools available to you.</p>


<h2><a name="ResponseFormats-XMLFormat"></a>XML Format</h2>

<p>The XML response format is a simple XML block.<br/>
To set the response format to XML, add the Accept request header with the text/xml value.</p>

<p>A successful call will return the following response (example of retrieving information about stock items):</p>

<div class="panel" style="border-width: 1px;"><div class="panelContent">
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div id="root">
		<pre class="theme: Default; brush: java; gutter: false">&lt;?xml version="1.0"?&gt;
&lt;magento_api&gt;
  &lt;data_item&gt;
    &lt;item_id&gt;1&lt;/item_id&gt;
    &lt;product_id&gt;1&lt;/product_id&gt;
    &lt;stock_id&gt;1&lt;/stock_id&gt;
    &lt;qty&gt;99.0000&lt;/qty&gt;
    &lt;low_stock_date&gt;&lt;/low_stock_date&gt;
  &lt;/data_item&gt;
  &lt;data_item&gt;
    &lt;item_id&gt;2&lt;/item_id&gt;
    &lt;product_id&gt;2&lt;/product_id&gt;
    &lt;stock_id&gt;1&lt;/stock_id&gt;
    &lt;qty&gt;100.0000&lt;/qty&gt;
    &lt;low_stock_date&gt;&lt;/low_stock_date&gt;
  &lt;/data_item&gt;
&lt;/magento_api&gt;</pre>
		</div>
</div></div>
</div></div>

<p>If an error occurs, the call may return the following response:</p>

<div class="panel" style="border-width: 1px;"><div class="panelContent">
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div id="root">
		<pre class="theme: Default; brush: java; gutter: false">&lt;?xml version="1.0"?&gt;
&lt;magento_api&gt;
  &lt;messages&gt;
    &lt;error&gt;
      &lt;data_item&gt;
        &lt;code&gt;404&lt;/code&gt;
        &lt;message&gt;Resource not found.&lt;/message&gt;
      &lt;/data_item&gt;
    &lt;/error&gt;
  &lt;/messages&gt;
&lt;/magento_api&gt;</pre>
		</div>
</div></div>
</div></div>

<h2><a name="ResponseFormats-JSONFormat"></a>JSON Format</h2>

<p>JSON (JavaScript Object Notation) is a lightweight data-interchange format.<br/>
To set the response format to JSON, add the Accept request header with the application/json value.</p>

<h3><a name="ResponseFormats-ResponseStructure"></a>Response Structure</h3>

<p>The JSON objects represent a direct mapping of the XML block from the XML response format.</p>

<p>A simple XML error</p>

<div class="panel" style="border-width: 1px;"><div class="panelContent">
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div id="root">
		<pre class="theme: Default; brush: java; gutter: false">&lt;messages&gt;
    &lt;error&gt;
      &lt;data_item&gt;
        &lt;code&gt;404&lt;/code&gt;
        &lt;message&gt;Resource not found.&lt;/message&gt;
      &lt;/data_item&gt;
    &lt;/error&gt;
  &lt;/messages&gt;</pre>
		</div>
</div></div>
</div></div>

<p>will be transformed to</p>

<div class="panel" style="border-width: 1px;"><div class="panelContent">
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div id="root">
		<pre class="theme: Default; brush: java; gutter: false">{"messages":{"error":[{"code":404,"message":"Resource not found."}]}}</pre>
		</div>
</div></div>
</div></div>


<h3><a name="ResponseFormats-JSONResponses"></a>JSON Responses</h3>

<p>A successful API call to the Stock Items resource will return the following XML response:</p>
<div class="panel" style="border-width: 1px;"><div class="panelContent">
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div id="root">
		<pre class="theme: Default; brush: java; gutter: false">&lt;?xml version="1.0"?&gt;
&lt;magento_api&gt;
  &lt;data_item&gt;
    &lt;item_id&gt;1&lt;/item_id&gt;
    &lt;product_id&gt;1&lt;/product_id&gt;
    &lt;stock_id&gt;1&lt;/stock_id&gt;
    &lt;qty&gt;99.0000&lt;/qty&gt;
    &lt;low_stock_date&gt;&lt;/low_stock_date&gt;
  &lt;/data_item&gt;
  &lt;data_item&gt;
    &lt;item_id&gt;2&lt;/item_id&gt;
    &lt;product_id&gt;2&lt;/product_id&gt;
    &lt;stock_id&gt;1&lt;/stock_id&gt;
    &lt;qty&gt;100.0000&lt;/qty&gt;
    &lt;low_stock_date&gt;&lt;/low_stock_date&gt;
  &lt;/data_item&gt;
&lt;/magento_api&gt;</pre>
		</div>
</div></div>
</div></div>

<p>The JSON equivalent will be as follows:</p>
<div class="panel" style="border-width: 1px;"><div class="panelContent">
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div id="root">
		<pre class="theme: Default; brush: java; gutter: false">[{"item_id":"1","product_id":"1","stock_id":"1","qty":"99.0000","low_stock_date":null},{"item_id":"2","product_id":"2","stock_id":"1","qty":"100.0000","low_stock_date":null}]</pre>
		</div>
</div></div>
</div></div>


<p>The list of HTTP status codes that are returned in the API response is described in the <a href="http://www.magentocommerce.com/api/rest/common_http_status_codes.html" title="Common HTTP Status Codes">Common HTTP Status Codes</a> part of the documentation. There, you can find the list of codes themselves together with their description.</p>

				    
<?php include(__ROOT__ . 'footer.php'); ?>
